/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package spartpartsmanager;

import java.util.ArrayList;

/**
 *
 * @author Ngocvan
 */
public class SPartComp extends SPart{
    private int numSub;
    
    private ArrayList<SPart> listSubs;

    public SPartComp(int numSub, ArrayList<SPart> listSubs, String code) {
        super(code);
        this.numSub = numSub;
        this.listSubs = listSubs;
        this.tier = 1;
    }
    
    public SPart findPart(String code){
        for (SPart sPart : listSubs) {
            if ( sPart.getCode().equals(code)) return sPart;
        }
        return null;
    }
    
    @Override
    public int  getPrice(){
        int sum = 0;
        for (SPart sPart : listSubs) {
            sum += sPart.getPrice();
        }
        return sum;
    }
    
    @Override
    public String toString(){
        StringBuilder str = new StringBuilder();
        str.append("[").append(code).append("]");
        for (SPart sPart : listSubs) {
            str.append(sPart.toString());
        }
        return str.toString();
    }
}
